﻿using System.Collections.Generic;
using System.Linq;
using System.Web.Mvc;
using Microsoft.VisualStudio.TestTools.UnitTesting;

namespace Mvc.RazorTools.FontAwesome.Tests
{
	[TestClass]
	public class FontAwesomeIconTests
	{
		[TestMethod]
		[TestCategory("FontAwesomeIcon")]
		public void FontAwesomeExpectedVersionTest()
		{
			Assert.AreEqual("4.3.0", FontAwesomeIconSet.Version);
		}

		[TestMethod]
		[TestCategory("FontAwesomeIcon")]
		public void FontAwesomeExpectedIconCountTest()
		{
			Assert.AreEqual(FontAwesomeIconSet.IconCount, FontAwesomeIconSet.AllItems.Count());
		}

		[TestMethod]
		[TestCategory("FontAwesomeIcon")]
		public void FontAwesomeIconConstructorTest1()
		{
			FontAwesomeIcon icon = new FontAwesomeIcon();
			Assert.AreEqual(string.Empty, icon.Name);
			Assert.AreEqual(false, icon.Locked);
			Assert.AreEqual(string.Empty, icon.IconId);
			Assert.AreEqual(0, icon.Unicode);
			Assert.AreEqual("0000", icon.HexCode);
			Assert.AreEqual("i", icon.HtmlTag);
			Assert.AreEqual("<i></i>", icon.Html.ToString());
		}

		[TestMethod]
		[TestCategory("FontAwesomeIcon")]
		public void FontAwesomeIconConstructorTest2()
		{
			FontAwesomeIcon icon = new FontAwesomeIcon("fa-test");
			Assert.AreEqual("fa-test", icon.Name);
			Assert.AreEqual(false, icon.Locked);
			Assert.AreEqual("fa-test", icon.IconId);
			Assert.AreEqual(0, icon.Unicode);
			Assert.AreEqual("0000", icon.HexCode);
			Assert.AreEqual("i", icon.HtmlTag);
			Assert.AreEqual("<i class=\"fa fa-test\"></i>", icon.Html.ToString());
		}

		[TestMethod]
		[TestCategory("FontAwesomeIcon")]
		public void FontAwesomeIconConstructorTest3()
		{
			FontAwesomeIcon icon = new FontAwesomeIcon("fa-test", 1);
			Assert.AreEqual("fa-test", icon.Name);
			Assert.AreEqual(false, icon.Locked);
			Assert.AreEqual("fa-test", icon.IconId);
			Assert.AreEqual(1, icon.Unicode);
			Assert.AreEqual("0001", icon.HexCode);
			Assert.AreEqual("i", icon.HtmlTag);
			Assert.AreEqual("<i class=\"fa fa-test\"></i>", icon.Html.ToString());
		}

		[TestMethod]
		[TestCategory("FontAwesomeIcon")]
		public void ImplicitCastToMvcHtmlString()
		{
			FontAwesomeIcon icon = FontAwesomeIconSet.Star;
			MvcHtmlString s = icon;
			Assert.AreEqual(icon.Html.ToString(), s.ToString());
		}

		[TestMethod]
		[TestCategory("FontAwesomeIcon")]
		public void ImplicitCastToString()
		{
			FontAwesomeIcon icon = FontAwesomeIconSet.Star;
			string s = icon;
			Assert.AreEqual(icon.Html.ToString(), s);
		}

		[TestMethod]
		[TestCategory("FontAwesomeIcon")]
		public void CreateTest1()
		{
			FontAwesomeIcon icon = FontAwesomeIcon.Create("fa-test");
			Assert.AreEqual("fa-test", icon.Name);
			Assert.AreEqual(false, icon.Locked);
			Assert.AreEqual("fa-test", icon.IconId);
			Assert.AreEqual(0, icon.Unicode);
			Assert.AreEqual("0000", icon.HexCode);
			Assert.AreEqual("i", icon.HtmlTag);
			Assert.AreEqual("<i class=\"fa fa-test\"></i>", icon.Html.ToString());
		}

		[TestMethod]
		[TestCategory("FontAwesomeIcon")]
		public void CreateTest2()
		{
			FontAwesomeIcon icon = FontAwesomeIcon.Create("fa-test", 1);
			Assert.AreEqual("fa-test", icon.Name);
			Assert.AreEqual(false, icon.Locked);
			Assert.AreEqual("fa-test", icon.IconId);
			Assert.AreEqual(1, icon.Unicode);
			Assert.AreEqual("0001", icon.HexCode);
			Assert.AreEqual("i", icon.HtmlTag);
			Assert.AreEqual("<i class=\"fa fa-test\"></i>", icon.Html.ToString());
		}

		[TestMethod]
		[TestCategory("FontAwesomeIcon")]
		public void CreateTest3()
		{
			FontAwesomeIcon icon = FontAwesomeIcon.Create("fa-test", 1, "Test");
			Assert.AreEqual("Test", icon.Name);
			Assert.AreEqual(false, icon.Locked);
			Assert.AreEqual("fa-test", icon.IconId);
			Assert.AreEqual(1, icon.Unicode);
			Assert.AreEqual("0001", icon.HexCode);
			Assert.AreEqual("i", icon.HtmlTag);
			Assert.AreEqual("<i class=\"fa fa-test\"></i>", icon.Html.ToString());
		}

		[TestMethod]
		[TestCategory("FontAwesomeIcon")]
		public void CreateTest4()
		{
			Dictionary<string, string> classAttributes = new Dictionary<string, string>();
			classAttributes.Add("item1", "value1");
			classAttributes.Add("item2", "value2");
			classAttributes.Add("item3", "value3");

			FontAwesomeIcon icon = FontAwesomeIcon.Create("fa-test", classAttributes);
			Assert.AreEqual("fa-test", icon.Name);
			Assert.AreEqual(false, icon.Locked);
			Assert.AreEqual("fa-test", icon.IconId);
			Assert.AreEqual(0, icon.Unicode);
			Assert.AreEqual("0000", icon.HexCode);
			Assert.AreEqual("i", icon.HtmlTag);
			Assert.AreEqual("<i class=\"fa fa-test value1 value2 value3\"></i>", icon.Html.ToString());
		}

		[TestMethod]
		[TestCategory("FontAwesomeIcon")]
		public void CreateTest5()
		{
			Dictionary<string, string> classAttributes = new Dictionary<string, string>();
			classAttributes.Add("item1", "value1");
			classAttributes.Add("item2", "value2");
			classAttributes.Add("item3", "value3");

			FontAwesomeIcon icon = FontAwesomeIcon.Create("fa-test", 1, classAttributes);
			Assert.AreEqual("fa-test", icon.Name);
			Assert.AreEqual(false, icon.Locked);
			Assert.AreEqual("fa-test", icon.IconId);
			Assert.AreEqual(1, icon.Unicode);
			Assert.AreEqual("0001", icon.HexCode);
			Assert.AreEqual("i", icon.HtmlTag);
			Assert.AreEqual("<i class=\"fa fa-test value1 value2 value3\"></i>", icon.Html.ToString());
		}

		[TestMethod]
		[TestCategory("FontAwesomeIcon")]
		public void CreateTest6()
		{
			FontAwesomeIcon icon = FontAwesomeIcon.Create("fa-test", 1, "Test", true, false);
			Assert.AreEqual("Test", icon.Name);
			Assert.AreEqual(true, icon.Locked);
			Assert.AreEqual("fa-test", icon.IconId);
			Assert.AreEqual(1, icon.Unicode);
			Assert.AreEqual("0001", icon.HexCode);
			Assert.AreEqual("i", icon.HtmlTag);
			Assert.AreEqual("<i class=\"fa fa-test\"></i>", icon.Html.ToString());
		}

		[TestMethod]
		[TestCategory("FontAwesomeIcon")]
		public void CreateTest7()
		{
			FontAwesomeIcon icon = FontAwesomeIcon.Create("fa-test", 1, "Test", false, false);
			Assert.AreEqual("Test", icon.Name);
			Assert.AreEqual(false, icon.Locked);
			Assert.AreEqual("fa-test", icon.IconId);
			Assert.AreEqual(1, icon.Unicode);
			Assert.AreEqual("0001", icon.HexCode);
			Assert.AreEqual("i", icon.HtmlTag);
			Assert.AreEqual("<i class=\"fa fa-test\"></i>", icon.Html.ToString());
		}

		[TestMethod]
		[TestCategory("FontAwesomeIcon")]
		public void CloneTest1()
		{
			FontAwesomeIcon icon1 = new FontAwesomeIcon("fa-test", 1);
			object icon2 = icon1.Clone();

			Assert.IsInstanceOfType(icon2, typeof(FontAwesomeIcon));
			Assert.AreNotSame(icon1, icon2);
			Assert.AreEqual("fa-test", ((FontAwesomeIcon)icon2).Name);
			Assert.AreEqual(false, ((FontAwesomeIcon)icon2).Locked);
			Assert.AreEqual("fa-test", ((FontAwesomeIcon)icon2).IconId);
			Assert.AreEqual(1, ((FontAwesomeIcon)icon2).Unicode);
			Assert.AreEqual("0001", ((FontAwesomeIcon)icon2).HexCode);
			Assert.AreEqual("i", ((FontAwesomeIcon)icon2).HtmlTag);
			Assert.AreEqual(icon1.Html.ToString(), ((FontAwesomeIcon)icon2).Html.ToString());
		}

		[TestMethod]
		[TestCategory("FontAwesomeIcon")]
		public void CloneTest2()
		{
			FontAwesomeIcon icon1 = FontAwesomeIcon.Create("fa-test", 1, "Test");
			object icon2 = icon1.Clone();

			Assert.IsInstanceOfType(icon2, typeof(FontAwesomeIcon));
			Assert.AreNotSame(icon1, icon2);
			Assert.AreEqual("Test", ((FontAwesomeIcon)icon2).Name);
			Assert.AreEqual(false, ((FontAwesomeIcon)icon2).Locked);
			Assert.AreEqual("fa-test", ((FontAwesomeIcon)icon2).IconId);
			Assert.AreEqual(1, ((FontAwesomeIcon)icon2).Unicode);
			Assert.AreEqual("0001", ((FontAwesomeIcon)icon2).HexCode);
			Assert.AreEqual("i", ((FontAwesomeIcon)icon2).HtmlTag);
			Assert.AreEqual(icon1.Html.ToString(), ((FontAwesomeIcon)icon2).Html.ToString());
		}

		[TestMethod]
		[TestCategory("FontAwesomeIcon")]
		public void CloneTest3()
		{
			FontAwesomeIcon icon1 = FontAwesomeIcon.Create("fa-test", 1);
			icon1.ClassAttributes.Add("item1", "value1");
			icon1.ClassAttributes.Add("item2", "value2");
			icon1.ClassAttributes.Add("item3", "value3");
			object icon2 = icon1.Clone();

			Assert.IsInstanceOfType(icon2, typeof(FontAwesomeIcon));
			Assert.AreNotSame(icon1, icon2);
			Assert.AreEqual("fa-test", ((FontAwesomeIcon)icon2).Name);
			Assert.AreEqual(false, ((FontAwesomeIcon)icon2).Locked);
			Assert.AreEqual("fa-test", ((FontAwesomeIcon)icon2).IconId);
			Assert.AreEqual(1, ((FontAwesomeIcon)icon2).Unicode);
			Assert.AreEqual("0001", ((FontAwesomeIcon)icon2).HexCode);
			Assert.AreEqual("i", ((FontAwesomeIcon)icon2).HtmlTag);
			Assert.AreEqual(icon1.Html.ToString(), ((FontAwesomeIcon)icon2).Html.ToString());
		}

		[TestMethod]
		[TestCategory("FontAwesomeIcon")]
		public void CloneLockedItemTest()
		{
			FontAwesomeIcon icon1 = FontAwesomeIcon.Create("fa-test", 1, "fa-test", true, false);
			icon1.ClassAttributes.Add("item1", "value1");
			icon1.ClassAttributes.Add("item2", "value2");
			icon1.ClassAttributes.Add("item3", "value3");
			object icon2 = icon1.Clone();

			Assert.IsInstanceOfType(icon2, typeof(FontAwesomeIcon));
			Assert.AreNotSame(icon1, icon2);
			Assert.AreEqual("fa-test", ((FontAwesomeIcon)icon2).Name);
			Assert.AreEqual(false, ((FontAwesomeIcon)icon2).Locked);
			Assert.AreEqual("fa-test", ((FontAwesomeIcon)icon2).IconId);
			Assert.AreEqual(1, ((FontAwesomeIcon)icon2).Unicode);
			Assert.AreEqual("0001", ((FontAwesomeIcon)icon2).HexCode);
			Assert.AreEqual("i", ((FontAwesomeIcon)icon2).HtmlTag);
			Assert.AreEqual(icon1.Html.ToString(), ((FontAwesomeIcon)icon2).Html.ToString());
		}

		[TestMethod]
		[TestCategory("FontAwesomeIcon")]
		public void SetIdTest()
		{
			FontAwesomeIcon icon = new FontAwesomeIcon();
			icon.IconId = "fa-test";
			Assert.AreEqual("fa-test", icon.Name);
			Assert.AreEqual(false, icon.Locked);
			Assert.AreEqual("fa-test", icon.IconId);
			Assert.AreEqual(0, icon.Unicode);
			Assert.AreEqual("0000", icon.HexCode);
			Assert.AreEqual("i", icon.HtmlTag);
			Assert.AreEqual("<i class=\"fa fa-test\"></i>", icon.Html.ToString());
			Assert.AreEqual(true, icon.ClassAttributes.ContainsKey("Id"));
			Assert.AreEqual(true, icon.ClassAttributes.ContainsKey("fa"));
		}

		[TestMethod]
		[TestCategory("FontAwesomeIcon")]
		[ExpectedException(typeof(ModifyLockedInstanceException))]
		public void SetIdWhenLockedTest()
		{
			FontAwesomeIcon icon = FontAwesomeIcon.Create("fa-test", 1, "Test", true, false);
			icon.IconId = "fa-something-else";
		}

		[TestMethod]
		[TestCategory("FontAwesomeIcon")]
		[ExpectedException(typeof(ModifyLockedInstanceException))]
		public void SetNameWhenLockedTest()
		{
			FontAwesomeIcon icon = FontAwesomeIcon.Create("fa-test", 1, "Test", true, false);
			icon.Name = "OtherName";
		}

		[TestMethod]
		[TestCategory("FontAwesomeIcon")]
		[ExpectedException(typeof(ModifyLockedInstanceException))]
		public void SetUnlockedWhenLockedTest()
		{
			FontAwesomeIcon icon = FontAwesomeIcon.Create("fa-test", 1, "Test", true, false);
			icon.Locked = false;
		}

		[TestMethod]
		[TestCategory("FontAwesomeIcon")]
		[ExpectedException(typeof(ModifyLockedInstanceException))]
		public void SetUnicodeWhenLockedTest()
		{
			FontAwesomeIcon icon = FontAwesomeIcon.Create("fa-test", 1, "Test", true, false);
			icon.Unicode = 1;
		}

		[TestMethod]
		[TestCategory("FontAwesomeIcon")]
		public void SetHtmlTagTest()
		{
			FontAwesomeIcon icon = FontAwesomeIcon.Create("fa-test");
			icon.HtmlTag = "span";
			Assert.AreEqual("<span class=\"fa fa-test\"></span>", icon.Html.ToString());
		}
	}
}
